package sg.edu.nus.iss.vmcs.store;

/**
 * Copyright 2003 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 */

/**
 
 * @version 3.0 5/07/2003
 * @author Olivo Miotto, Pang Ping Li
 */

/**
* A Store is a generic Store to add  Store Items both Drinks Brand Item 
*  and   Coins Item into the Store and retrieve  Store Items from the 
* Store.
*/


public abstract class Store {
	public final static int CASH  = 1;
	public final static int DRINK = 2;

	protected int size;

	protected StoreItem items[];

	/**
	* Store contains two overloaded Constructors .This constructor creates   
	*  a new instances of Store without parameter.
	* @see 		Store
	*/

	public Store() {
	}
	
	/**
	* This constructor creates a new instances of Store with integer       
	*  Parameter    
	* @param itemn list contains the Store Items contained in the Store
	* @see 		Store
	*/

	public Store(int itemn) {
		size = itemn;
		items = new StoreItem[size];
	}
	/**
	* This operation sets the size of the items array in the Store.
	* @param	sz	total numbers of Drinks Brand Item or Coins Item in 
	*  the store (size of the Store)
	* @see		Store
	*/

	public void setStoreSize(int sz) {
		size = sz;
		items = new StoreItem[size];
	}
	
	/**
	* This operation gets the size of the items array in the Store.
	* @return		the array of StoreItem object in the Store
	* @see		Store
	*/
	
	public StoreItem[] getItems() {
		return items;
	}
	
	/**
	* This operation adds Store Items into the Store.
	* @param 	idx		the index number to identify the Drinks Brand  
	*  Item or Coins Item in the Store
	* @param	object		the StoreItem (either Drinks or Coins) to 
	*  add to the Store
	* @see 		Store
	*/


	public void addItem(int idx, StoreItem object) {
		if ((idx >= size) || (idx < 0))
			return;
		items[idx] = object;
	}
	/**
	* This operation returns the Store Item corresponding to the index 
	* entered.
	* @param	idx		the index number to identify the Drinks Brand  
	*  Item or Coins Item in the Store
	* @return 			the StoreItem corresponding to the index 
	* entered
	* @see		Store
	*/

	public StoreItem getStoreItem(int idx) {
		if ((idx >= size) || (idx < 0))
            return null;
		return items[idx];
	}
	/**
	* This operation finds a Store Object in the store with a specified name.
	*
	* @param 	name	the name of Store Object (Drinks name or Coins name)
	* @return 			the StoreObject found in the store based on specific name
	* @see		Store
	*/
	public StoreObject findObject(String name) {
		String en;
		StoreObject so;
		int i;

		for (i = 0; i < size; i++) {
			if (items[i] == null)
				return null;
			so = items[i].getContent();
			if (so == null)
				return null;
			en = so.getName();
			if (en != null) {
				if (en.compareTo(name) == 0)
					return so;
			}
		}
		return null;
	}
	/**
	* This operation sets the total number of  store items held.
	*
	* @param	idx 	the index number to identify Drinks Brand Item or Coins Item in the Store
	* @param 	qty		total quantity number of Drinks or Coins for corresponding index identifier
	* @see 		Store
	*/
	public void setQuantity(int idx, int qty) {
		System.out.println("Store: setQauntity- qty=" + qty);
		if ((idx >= size) || (idx < 0))
			return;
		items[idx].setQuantity(qty);
	}
	/**
	* This operation gets the size of the items array in the Store.
	*
	* @return 		total numbers of Drinks Brand Item or Coins Item in the Store (size of Store)
	* @see		Store
	*/

	public int getStoreSize() {
		return size;
	}

}
